﻿using LJ.Abstractions.Extensions;
using LJ.DataAccess.Abstractions.DataObject;
using LJ.DataAccess.EntityFrameworkCore.Internal;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LJ.DataAccess.EntityFrameworkCore.PostgreSQL.Internal;

public class EFPostgreDataObjectMap : EFDataObjectMapBase
{
    public override void ConfigureDataObjectMap(ModelBuilder modelBuilder)
    {
        foreach (var entityType in modelBuilder.Model.GetEntityTypes())
        {
            if (entityType.ClrType.IsDeriveClassFrom(typeof(IEntityObject)))
            {
                modelBuilder.Entity(entityType.ClrType).HasKey(nameof(IEntityObject.Id));

                modelBuilder.Entity(entityType.ClrType).Property(nameof(IEntityObject.Version)).IsRowVersion();
            }
        }
    }
}
